﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DataContracts;

namespace ServiceImplementation.Translator
{
    /// <summary>
    /// Define RoleDTO Translator
    /// </summary>
    class RoleDTOTranslator
    {
        /// <summary>
        /// To Translate RoleDTO to RoleBusinessEntity
        /// </summary>
        /// <param name="roleDTO"></param>
        /// <returns></returns>
        public static BLL.Role TranslateDTOToBusiness(DataContracts.RoleDTO roleDTO)
        {
            BLL.Role roleBE = new BLL.Role();
            roleBE.RoleId = roleDTO.RoleId;
            roleBE.RoleName = roleDTO.RoleName;
            roleBE.Status = StatusDTOTranslator.TranslateDTOToBusiness(roleDTO.Status);
            roleBE.Authorities = new List<BLL.Authority>();
            if (roleDTO.Authorities != null)
            {              
                foreach (AuthorityDTO item in roleDTO.Authorities)
                {
                         roleBE.Authorities.Add(AuthorityDTOTranslator.TranslateDTOToBusiness(item));
                   
                }
            }
            return roleBE;
        }

        /// <summary>
        /// To Translate RoleBusinessEntity to RoleDTO
        /// </summary>
        /// <param name="roleBE"></param>
        /// <returns></returns>
        public static DataContracts.RoleDTO TranslateBusinessToDTO(BLL.Role roleBE)
        {
            DataContracts.RoleDTO roleDTO = new DataContracts.RoleDTO();
            roleDTO.RoleId = roleBE.RoleId;
            roleDTO.RoleName = roleBE.RoleName;
            roleDTO.Status = StatusDTOTranslator.TranslateBusinessToDTO(roleBE.Status);
            roleDTO.Authorities = new List<AuthorityDTO>();
            if (roleBE.Authorities != null)
            {              
                foreach (BLL.Authority item in roleBE.Authorities)
                {
                         roleDTO.Authorities.Add(AuthorityDTOTranslator.TranslateBusinessToDTO(item));
                  
                }
            }
            return roleDTO;
        }
    }
}
